<template>
  <div class="index">
    <el-container>
      <el-header>
        <!-- 头部 -->
        <div class="header_top">
          <div class="header_left">
            <img src="../assets/1.png" alt="" class="header_img" />
            <p class="header_text">电商后台管理系统</p>
          </div>
          <el-button type="info" @click="out">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse?'60px':'200px'">
          <!-- 侧边栏 -->
          <p class="aside_p" @click="isCollapse = !isCollapse">|||</p>
          <!-- @open="handleOpen" @close="handleClose" -->
          <el-menu
            :collapse="isCollapse"
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409eff"
            unique-opened
            router
          >
            <el-submenu
              :index="item.path"
              v-for="(item, index) in Menus"
              :key="item.id"
            >
              <template slot="title">
                <i :class="icon[item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                :index="'/' + ele.path"
                v-for="(ele, i) in item.children"
                :key="ele.id"
              >
                <i class="el-icon-menu"></i>
                <span>{{ ele.authName }}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 坑 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { pleaMenus } from "../utils/http";
export default {
  data() {
    return {
      Menus: [], //侧边栏
      isCollapse: false,
      icon: {
        125: "el-icon-user-solid",
        103: "el-icon-s-opportunity",
        101: "el-icon-s-shop",
        102: "el-icon-s-unfold",
        145: "el-icon-s-marketing",
      },
    };
  },
  created() {
    this.menus();
  },
  methods: {
    out() {
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
    menus() {
      pleaMenus().then((res) => {
        // console.log(res);
        this.Menus = res.data;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-header {
  background-color: #373d41;
  color: #fff;
  padding: 0;
  .header_top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 20px;
    .header_left {
      display: flex;
      align-items: center;
      .header_img {
        width: 60px;
        height: 60px;
        margin-right: 20px;
      }
      .header_text {
        font-size: 22px;
      }
    }
  }
}

.el-aside {
  background-color: #333744;
  color: #fff;
  // height: calc(100vh - 60px);
  // height: 100%;
  .aside_p {
    text-align: center;
    background-color: #4a5064;
    cursor: pointer;
  }
}
.el-breadcrumb{
  margin-bottom: 20px;
}
.el-main {
  background-color: #e9eef3;
  // height: 100vh;
  height: calc(100vh - 60px);
}
</style>